<?php
	require_once('assert.php');
	require_once(dirname(__FILE__) . '/../viae/createImageFile.php');
	require_once (dirname(__FILE__) . '/../viae/converter.php');
	
	//createImageFile($uploadDir, $width, $height, $scale, $img)
	
	$uploadDir = dirname(__FILE__) . '/tmp/';
	
	$path = dirname(__FILE__) . '/img/a.jpg';
	$data = file_get_contents($path);
	assertNotNull($data, "image");
	$type = pathinfo($path, PATHINFO_EXTENSION);
	$base64Image = 'data:image/' . $type . ';base64,' . base64_encode($data);
	assertNotNull($base64Image, "base64 image");
	
	echo '<br/>Scenario 1<br/><br/>';
	$widthCm = 10;
	$heightCm = 5;
	$scale = 1;
	$pdf = createImageFile($uploadDir, cmToPixel($widthCm), cmToPixel($heightCm), $scale, $base64Image, $type);
	assertEquals(5, $pdf->h, "width");
	assertEquals(10, $pdf->w ,"height");
	assertEquals("L", $pdf->CurOrientation, "CurOrientation");
	assertEquals("L", $pdf->DefOrientation, "DefOrientation");
	
	echo '<br/>Scenario 2<br/><br/>';
	$widthCm = 5;
	$heightCm = 10;
	$scale = 1;
	$pdf = createImageFile($uploadDir, cmToPixel($widthCm), cmToPixel($heightCm), $scale, $base64Image, $type);
	//in portrait mode, if the width > height ==> height becomes the width and the other way around
	assertEquals(10, $pdf->h, "width");
	assertEquals(5, $pdf->w,"height");
	assertEquals("P", $pdf->CurOrientation, "CurOrientation");
	assertEquals("P", $pdf->DefOrientation, "DefOrientation");
	
	echo '<br/>Scenario 3<br/><br/>';
	$widthCm = 15;
	$heightCm = 5;
	$scale = 0.5;
	$pdf = createImageFile($uploadDir, cmToPixel($widthCm), cmToPixel($heightCm), $scale, $base64Image, $type);
	assertEquals(10, $pdf->h, "width");
	assertEquals(30, $pdf->w ,"height");
	assertEquals("L", $pdf->CurOrientation, "CurOrientation");
	assertEquals("L", $pdf->DefOrientation, "DefOrientation");
	
	echo '<br/>Scenario 4<br/><br/>';
	$widthCm = 5;
	$heightCm = 15;
	$scale = 0.5;
	$pdf = createImageFile($uploadDir, cmToPixel($widthCm), cmToPixel($heightCm), $scale, $base64Image, $type);
	assertEquals(30, $pdf->h, "width");
	assertEquals(10, $pdf->w ,"height");
	assertEquals("P", $pdf->CurOrientation, "CurOrientation");
	assertEquals("P", $pdf->DefOrientation, "DefOrientation");
	
	echo '<br/>Scenario 5<br/><br/>';
	$widthCm = 30;
	$heightCm = 10;
	$scale = 2;
	$pdf = createImageFile($uploadDir, cmToPixel($widthCm), cmToPixel($heightCm), $scale, $base64Image, $type);
	assertEquals(5, $pdf->h, "width");
	assertEquals(15, $pdf->w ,"height");
	assertEquals("L", $pdf->CurOrientation, "CurOrientation");
	assertEquals("L", $pdf->DefOrientation, "DefOrientation");
	
	echo '<br/>Scenario 6<br/><br/>';
	$widthCm = 10;
	$heightCm = 30;
	$scale = 2;
	$pdf = createImageFile($uploadDir, cmToPixel($widthCm), cmToPixel($heightCm), $scale, $base64Image, $type);
	assertEquals(15, $pdf->h, "width");
	assertEquals(5, $pdf->w ,"height");
	assertEquals("P", $pdf->CurOrientation, "CurOrientation");
	assertEquals("P", $pdf->DefOrientation, "DefOrientation");
	
	//var_dump($pdf);
	
?>